import java.util.Arrays;
class Solution {
    private List<List<Integer>> result = new ArrayList<>();
    private List<Integer> subSet = new ArrayList();
    private int k;

    public List<List<Integer>> combine(int n, int k) {
        this.k = k;
        findSubSet(n, 1);
        return result;
    }

    private void findSubSet(int n, int index) {
        if (subSet.size() > this.k || subSet.size() + n - index + 1 < this.k) {
            return;
        }
        if (index > n) {
            result.add(new ArrayList<>(subSet));
            return;
        }
        subSet.add(index);
        findSubSet(n, index + 1);
        subSet.remove(subSet.size() - 1);

        findSubSet(n, index + 1);
    }
}
